package com.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.dao.TargetTypeDAO;
import com.rev.Target;
import com.rev.Targettype;
import com.rev.TargettypeHome;
import com.util.HibernateUtil;

public class TargetTypeDAOImpl implements TargetTypeDAO{
	private TargettypeHome tth = new TargettypeHome(); 
	
	public boolean insert(Targettype targetType) {
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Transaction  transaction = session.beginTransaction();
			tth.attachDirty(targetType);
			transaction.commit();
			session.close();
			return true;
		} catch (Exception e) {}
		return false;
	}

	public boolean update(Targettype targetType) {
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Transaction  transaction = session.beginTransaction();
			tth.attachDirty(targetType);
			transaction.commit();
			session.close();
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	public boolean delete(Targettype targetType) {
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Transaction  transaction = session.beginTransaction();
			tth.delete(targetType);
			transaction.commit();
			session.close();
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	public Targettype findById(int id) {
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			session.beginTransaction();
			Targettype s = tth.findById(id);
			session.getTransaction().commit();
			session.close();
			return s;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;

	}

	public Targettype findByRef(String ref) {
		return null;
	}

	public List<Target> findTargets(Targettype targetType) {
		return null;
	}

	public List<Targettype> findAll() {

		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			session.beginTransaction();
			List list = tth.findByExample(new Targettype());
			session.getTransaction().commit();
			session.close();
			return list;
		} catch (Exception e) {
		}
		return null;
	}
}
